<template>
  <div class="app-container">
    <van-nav-bar :title="current" left-arrow @click-left="$router.back()" />
    <div class="content-box ticket" v-if="current == '报名票卷'">
      <div class="card info">
        <img class="cover-img" :src="require(`@/assets/images/activityRegister/activity_item_cover.png`)">
        <div class="info-box">
          <div class="label">{{ detailData.title }}</div>
          <div class="tip">截止日期：{{ detailData.date }}</div>
        </div>
      </div>
      <div class="card ticket">
        <div class="check-box" />
        <div class="title">免费票</div>
        <div class="price">￥{{ detailData.price || '免费' }}</div>
        <div class="tip">备注说明:免费</div>
      </div>
    </div>
    <div class="content-box form" v-if="current == '报名信息'">
      <div class="form-box">
        <el-form ref="formRef" class="form" :model="form" :rules="formRules" label-width="51px">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入姓名" />
          </el-form-item>
          <el-form-item label="性别" prop="gender">
            <!-- <el-input v-model="form.gender" placeholder="请选择性别" /> -->
            <el-radio v-model="form.gender" label="男">男</el-radio>
            <el-radio v-model="form.gender" label="女">女</el-radio>
          </el-form-item>
          <el-form-item label="手机" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入手机号码" />
          </el-form-item>
          <el-form-item label="单位" prop="department">
            <el-input v-model="form.department" placeholder="请输入单位" />
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="card handle" v-if="current == '报名票卷'">
      <div class="btn" @click="nextStep">下一步</div>
    </div>
    <div class="card handle" v-if="current == '报名信息'">
      <div class="btn" @click="submit">立即报名</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ActivityRegisterRegister',
  data() {
    return {
      current: '报名票卷',
      detailData: { title: 'AI技术讲解AI技术讲解AI技术讲解AI技术讲解', date: '2025年2月12日', price: '' },
      form: {
        name: '',
        phone: '',
      },
      formRules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'change' }],
        gender: [{ required: true, message: '请选择性别', trigger: 'change' }],
        phone: [{ required: true, message: '请输入手机号码', trigger: 'change' }],
        department: [{ required: true, message: '请输入单位', trigger: 'change' }],
      },
    };
  },
  methods: {
    nextStep() {
      this.current = '报名信息';
    },
    submit() {
      this.$refs.formRef.validate((valid) => {
        if (!valid) return;
        this.$message({ message: '报名成功', type: 'success' });
        this.$router.push('/activityRegister/index');
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.content-box {
  width: calc(100% - 30px);
  height: calc(100% - 135px);
  padding: 10px 15px;
  display: flex;
  flex-direction: column;
}

.card {
  border-radius: 10px;
  padding: 15px;
  background-color: #fff;
  margin-bottom: 15px;

  &.info {
    display: flex;

    .cover-img {
      width: 25%;
      margin-right: 15px;
    }

    .info-box {
      flex: 1;
      padding: 5px 0;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .label {
        font-size: 15px;
      }

      .tip {
        font-size: 14px;
        color: #8b8b8b;
      }
    }
  }

  &.ticket {
    position: relative;
    border: 0.6px solid #165dff;

    .check-box {
      display: inline-block;
      position: absolute;
      right: -1px;
      top: 0;
      border: 1px solid #dcdfe6;
      border-top-right-radius: 10px;
      box-sizing: border-box;
      width: 40px;
      height: 30px;
      background-color: #fff;
      z-index: 1;
      transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
        background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
      background-color: #165dff;
      border-color: #165dff;

      &:after {
        box-sizing: content-box;
        content: '';
        border: 3px solid #fff;
        border-left: 0;
        border-top: 0;
        height: 14px;
        position: absolute;
        left: 15px;
        top: 3px;
        transform: rotate(45deg) scaleY(0);
        width: 6px;
        transition: transform 0.15s ease-in 0.05s;
        transform-origin: center;
        transform: rotate(45deg) scaleY(1);
      }
    }

    .title {
      margin-bottom: 15px;
      font-size: 18px;
      font-weight: bold;
    }

    .price {
      margin-bottom: 15px;
      font-weight: bold;
      color: #165dff;
    }

    .tip {
      padding-top: 10px;
      border-top: 1px solid #d8d8d8;
      font-size: 14px;
      color: #8b8b8b;
    }
  }
  &.handle {
    flex-shrink: 0;
    margin-bottom: 0px;
    display: flex;
    justify-content: end;

    .btn {
      padding: 7px 30px;
      border-radius: 20px;
      background-color: #165dff;
      color: #fff;
      cursor: pointer;
    }
  }
}
.form-box {
  width: 100%;
  ::v-deep .el-form {
    .el-form-item {
      margin-bottom: 20px;
      padding: 5px 10px;
      border-radius: 10px;
      background-color: #fff;
      .el-form-item__error {
        padding-top: 8px;
      }
      .el-input__inner {
        border: none;
      }
      .el-radio {
        margin-left: 20px;
      }
    }
  }
}
</style>
